package com.shijiwei.lifthelper.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.shijiwei.lifthelper.R;

import org.xutils.common.util.LogUtil;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/12/19.
 */
public class OurAdapter extends AppBaseAdapter {

    public OurAdapter(List<String> list, Context context) {
        super(list, context);
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            convertView = inflater.inflate(R.layout.item_listview_our,parent,false);
            holder = new ViewHolder(convertView);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String title = (String) list.get(position);
        holder.titleText.setText(title);
        holder.extraLayout.setVisibility(View.GONE);

        return convertView;
    }

    private class ViewHolder extends BaseViewHolder{

        @ViewInject(R.id.tv_item_our_title)
        private TextView titleText;
        @ViewInject(R.id.ll_item_our)
        private LinearLayout extraLayout;
        @ViewInject(R.id.tv_item_our_body)
        private TextView bodyText;
        @ViewInject(R.id.btn_item_our)
        private Button itemBtn;

        public ViewHolder(View convertView) {
            super(convertView);
            x.view().inject(this,convertView);
        }
    }

    public void displaySecondItem(View view, int position){
        ViewHolder holder = (ViewHolder) view.getTag();

        if (holder.extraLayout.getVisibility() == View.VISIBLE){

            holder.extraLayout.setVisibility(View.GONE);
        } else {

            holder.extraLayout.setVisibility(View.VISIBLE);
            switch (position){
                case 0:
                    holder.bodyText.setText("当前版本 : 1.0.1");
                    holder.itemBtn.setText("检索更新");
                    break;
                case 1:
                    holder.bodyText.setText("温馨小提示："+"\n"
                    +"\u3000\u3000"+"在某些页面（如：收藏）可以长按删除哟！");
                    holder.itemBtn.setVisibility(View.GONE);
                    break;
                case 2:
                    holder.bodyText.setText("相信像我们这样优秀的应用，你一定不会有什么意见吧！");
                    holder.itemBtn.setVisibility(View.GONE);
                    break;
                case 3:
                    holder.bodyText.setText("此应用版权已经牢牢地握在我们的手中，伪者必究！！");
                    holder.itemBtn.setVisibility(View.GONE);
                    break;
            }
            holder.itemBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(context,"您当前版本已经是最新的了",Toast.LENGTH_SHORT).show();
                }
            });
        }
    }
}
